#include <stdio.h>
#include <stdlib.h>
#include "LinkCircleQueueu.h"

//初始化
int LCQueueInit(LCQueue* lcq)
{
    return DClistInit(&lcq->queue);
}

//销毁队列
void LCQueueDestroy(LCQueue* lcq)
{
    DClistDestroy(&lcq->queue);
}

//打印队列
void LCQueuePrint(LCQueue* lcq)
{
    if(lcq->queue.len == 0)
        return;
    Node* cur = lcq->queue.head;
    while(cur != lcq->queue.tail)
    {
        printf("%d ", cur->data);
        cur = cur->next;
    }
    printf("%d ", lcq->queue.tail->data);
    printf("\n");
}

//入队
void LCQueuePush(LCQueue* lcq, ElementType element)
{
    DClistInsertTail(&lcq->queue, element);
}

//出队
ElementType* LCQueuePop(LCQueue* lcq)
{
    if(lcq->queue.len == 0)
    {
        printf("Queue is empty!\n");
        return NULL;
    }
    lcq->FrontData = lcq->queue.head->data;
    DClistRemoveByIndex(&lcq->queue, 0);
    return &lcq->FrontData;
}

//判空
int LCQueueIsEmpty(LCQueue* lcq)
{
    if(lcq->queue.len == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

//获取队首元素
ElementType LCQueueGetFront(LCQueue* lcq)
{
    return lcq->queue.head->data;
}

//获取队列有效元素个数
int LCQueueSize(LCQueue* lcq)
{
    return lcq->queue.len;
}



